function initialAdd(scopeObject1,scopeObject2,actBoolean){
        require(['angular','directives'],function (angular) {
            var app = angular.module('app', ['directives']);
            app.controller('ActivityController',['$scope','$compile','$timeout',function ($scope,$compile,$timeout) {
                    $scope.activity = scopeObject1;
                    if(actBoolean.model_id){
                        $scope.activity.previewData = {
                            'time':$scope.activity.basic.time,
                            'background':'{{$activity->backgroundImg}}'
                        }
                        $scope.activity.preview_src="/{{$activity->model->rule}}/activity/preview/{{$activity->model->rule}}/{{$activity->template->template}}"
                    }
                    $scope.previewDataFunc = function () {
                        return JSON.stringify($scope.activity.previewData);
                    };
                    window.uploadFilesSuccess = function (result,input_name) {
                        if (input_name == 'backgroundImg'){
                            $timeout(function () {
                                console.log($scope.activity,'uploadFilesSuccess');
                                $scope.activity.previewData['background'] = result.url;
                            })
                        }
                    }
                    $scope.$watch('previewDataFunc()',function (newData) {
                        if (newData){
                            newData = JSON.parse(newData);
                            $urlPath = parseURL($scope.activity.preview_src);
                            $scope.activity.preview_src =$urlPath['path']+'?'+$.param(newData);
                        }
                    });
                    //活动落地页或自定义落地页
                    $scope.selectLandindPage =function (landindPage) {
                        if ($scope.activity.share.landindPage == landindPage){
                            $scope.activity.share.landindPage = 0;
                        }else {
                            $scope.activity.share.landindPage = landindPage;
                        }
                    };
                    $scope.removeAddedPrices =function (obj) {
                        _.remove($scope.activity.prizes,function (n) {
                            return n.id ==obj.id;
                        });
                        _.remove($scope.activity.specs,function (n) {
                            return n.prize ==obj.id;
                        });
                        var exclude = _.map($scope.activity.prizes, 'id');
                        $('.prizes-table').attr('data-exclude',exclude.join(','));
                    }

                    $scope.addSpec = function () {
                        if ($scope.activity.prizes.length == 0) {
                            utils.showNotification('请先添加奖品,然后再设置特殊规则', 3);
                            return false;
                        }
                        var spec = {
                            start:'',
                            end:'',
                            prize:$scope.activity.prizes[0].id,
                            times:0
                        };
                        if ($scope.activity.specs.length >0){
                            spec['id'] = _.last($scope.activity.specs)['id']+1;
                        }else {
                            spec['id'] = 0;
                        }
                        $scope.activity.specs.push(spec);
                    }
                    $scope.removeSpec = function (spec) {
                        _.remove($scope.activity.specs,function (n) {
                            return n.id == spec.id;
                        });
                    }
                    $scope.onFinishWizard =function() {
                        //here you can do something, sent the form to server via ajax and show a success message with swal
                        tinyMCE.triggerSave();
                        if (valideActivityForm()){
                            var obj = $('#activityForm').serialize();
                            console.log(obj);
                            $.isLoading({text:'数据提交中，请稍后。。。'});
                            $.post(location.href,obj,function (res) {
                                $.isLoading('hide');
                                if(res.code == 0){
                                    var notify = utils.showNotification('保存成功', 2);
                                    setTimeout(function () {
                                        notify.close();
                                        window.location.href="/web/activity/index";
                                    },2000);
                                }else {
                                    utils.showNotification(res.message,3);
                                }
                            });
                        }
                    }
                    $scope.openSpec=function() {
                        $scope.activity.specs_isopen = $scope.activity.specs_isopen == 1?0:1;
                    };
                    $scope.$on('bootstrap-switch-change',function (event,data) {
                        $scope.$apply(
                            function () {
                                console.log(data,'bootstrap-switch-change data');
                                // if(data.type=='vote_group'){
                                //     if (data.value){
                                //         $scope.activity.specs_isopen = 1;
                                //     }else {
                                //         $scope.activity.specs_isopen = 0;
                                //     }
                                // }else{
                                    if (data.value){
                                        $scope.activity.specs_isopen = 1;
                                    }else {
                                        $scope.activity.specs_isopen = 0;
                                    }
                                // }
                            }
                        );
                    })
                    window.operateEvents = {
                        'click .selectPrize':function (e,value,row) {
                            $scope.$apply(function () {
                                row.winning_limit = 0;
                                row.stock_limit = 0;
                                row.winning_probability = 0;
                                row.available_stock =row.available_stock || 0;
                                row.max_amount = 0;
                                if (row.type_code == 'wechat' || row.type_code == 'alipay'){
                                    row.type ="redpack";
                                }else {
                                    row.type ="other";
                                }
                                $scope.activity.prizes.push(row);
                                var exclude = _.map($scope.activity.prizes, 'id');
                                $('.prizes-table').attr('data-exclude',exclude.join(','));
                            });
                        }
                    };
                    //新建活动类型选择
                    $('.category-select').on('click', function () {
                        $('#wizardCard').bootstrapWizard('next');
                        var category = $(this).data('category');
                        $('input[name="category"]').val(category);
                        $scope.$apply(function () {
                            $scope.activity =$.extend({},{category:category},scopeObject2);
                        });
                    })
                    //新建活动模板选择
                    $(document).on('click','.select-template',function () {
                        var model = $(this).data('model');
                        var tpl = $(this).data('detail');
                        console.log(tpl,'template tpl');
                        $('input[name="model_id"]').val(tpl.model_id);
                        $('input[name="template_id"]').val(tpl.id);
                        // $('input[name="activity_type"]').val(tpl.activity_type);
                        $timeout(function () {
                            $scope.activity.preview_src ='/'+tpl.model.rule+'/activity/preview/'+tpl.model.rule+'/'+tpl.template;
                        });
                        window.redpack_config={
                            'isBackgroundImage':tpl.isBackgroundImage,
                            'isBackgroundColor':tpl.isBackgroundColor
                        };
                        // if (tpl.isBackgroundImage == 1){
                        //     $('.backgroundImg-container').show();
                        // }else {
                        //     $('.backgroundImg-container').hide();
                        // }
                        // if (tpl.isBackgroundColor == 1){
                        //     $('.backgroundColor-container').show();
                        // }else {
                        //     $('.backgroundColor-container').hide();
                        // }
                        $.get('/web/modelRule',{model:model},function (res) {
                            $('.activity_tab').html($compile(res)($scope));
                        });
                        $('#wizardCard').bootstrapWizard('next');
                    })

                    if(actBoolean.id){
                        $.get('/web/modelRule',{model:"{{$activity->model_id}}" },function (res) {
                            $scope.$apply(function () {
                                $('#activity_tab_1').html($compile(res)($scope));
                                var exclude = _.map($scope.activity.prizes, 'id');
                                $('#activity_tab_1').find('.prizes-table').attr('data-exclude',exclude.join(','));
                            });
                        });
                        var tpl = $('a[data-template="{{$activity->template_id}}"]').data('detail');
                        if (tpl.isBackgroundImage == 1){
                            $('.backgroundImg-container').show();
                        }else {
                            $('.backgroundImg-container').hide();
                        }
                        if (tpl.isBackgroundColor == 1){
                            $('.backgroundColor-container').show();
                        }else {
                            $('.backgroundColor-container').hide();
                        }
                        $('.card-wizard').find('.btn-back').hide();
                    }

                    function valideActivityForm() {
                        var form = $('#activityForm');
                        var category =$('input[name="category"]').val();
                        if (!form.find('input[name=name]').val()){
                            utils.showNotification('请输入活动名称',3);
                            return false;
                        }
                        if (!form.find('input[name=startTime]').val()){
                            utils.showNotification('请输入活动开始时间',3);
                            return false;
                        }
                        if (!form.find('input[name=endTime]').val()){
                            utils.showNotification('请输入活动结束时间',3);
                            return false;
                        }
                        if (moment(form.find('input[name=endTime]').val()).unix()< moment(form.find('input[name=startTime]').val()).unix()){
                            utils.showNotification('活动结束时间不能小于开始时间',3);
                            return false;
                        }
                        if(form.find('input[name="limit[num]"]').val() ==""){
                            utils.showNotification('请输入参与活动次数',3);
                            return false;
                        }

                        if (typeof valideRuleForm !== 'undefined' && $.isFunction(valideRuleForm)){
                            var res = valideRuleForm();
                            if (!res){
                                return false;
                            }
                        }
                            if ($scope.activity.prizes.length > 0 && $scope.activity.specs_isopen == 1){
                                var isSuccess = true,errmsg="";
                                _.each($scope.activity.specs,function (v) {
                                    var start = $('input[name="rule[spec][list]['+v.id+'][start]"]').val();
                                    var end = $('input[name="rule[spec][list]['+v.id+'][end]"]').val();
                                    if (!start){
                                        isSuccess = false;
                                        errmsg = "请设置特殊规则的开始时间";
                                        return false;
                                    }
                                    if (!end){
                                        isSuccess = false;
                                        errmsg = "请设置特殊规则的结束时间";
                                        return false;
                                    }
                                    if (moment(start).unix() >= moment(end).unix()){
                                        isSuccess = false;
                                        errmsg = "特殊规则的开始时间不能大于或等于结束时间";
                                        return false;
                                    }
                                })
                                if (!isSuccess){
                                    utils.showNotification(errmsg,3);
                                    return false;
                                }
                            }
                        if (category == 1){
                            if (form.find('input[name="share[isopen]"]').is(':checked')){
                                if (!form.find('input[name="share[icon]"]').val()){
                                    utils.showNotification('请上传分享图标',3);
                                    return false;
                                }
                                if (!form.find('input[name="share[title]"]').val()){
                                    utils.showNotification('请输入分享标题',3);
                                    return false;
                                }
                                if (!form.find('textarea[name="share[description]"]').val()){
                                    utils.showNotification('请输入分享文案',3);
                                    return false;
                                }
                                if (!form.find('input[name="share[qrcode]"]').val()){
                                    utils.showNotification('请上传二维码',3);
                                    return false;
                                }
                            }
                        }else {
                            if (!form.find('input[name="share[icon]"]').val()){
                                utils.showNotification('请上传分享图标',3);
                                return false;
                            }
                            if (!form.find('input[name="share[title]"]').val()){
                                utils.showNotification('请输入分享标题',3);
                                return false;
                            }
                            if (!form.find('textarea[name="share[description]"]').val()){
                                utils.showNotification('请输入分享文案',3);
                                return false;
                            }

                            if (form.find('input[name="share[landindPage]"]:checked').val() == 1){
                                if (!form.find('input[name="share[qrcode]"]').val()){
                                    utils.showNotification('请上传底部图片',3);
                                    return false;
                                }
                                if (!form.find('input[name="share[download][ios]"]').val()){
                                    utils.showNotification('请输入IOS下载地址',3);
                                    return false;
                                }
                                if (!form.find('input[name="share[download][android]"]').val()){
                                    utils.showNotification('请输入安卓下载地址',3);
                                    return false;
                                }
                            }
                            if (form.find('input[name="share[landindPage]"]:checked').val() == 2){
                                if (!form.find('input[name="share[share_url]"]').val()){
                                    utils.showNotification('请自定义落地页面地址',3);
                                    return false;
                                }
                            }
                        }
                        return true;
                    }
            }]);
            angular.bootstrap(document, ['app']);
        });
        /*初始化竞猜中的方法*/
        // initialCompetitionOpt();
        var bootstrapWizard = $('#wizardCard').bootstrapWizard({
            tabClass: 'nav nav-pills-steelblue',
            nextSelector: '.btn-next',
            previousSelector: '.btn-back',
            onNext: function (tab, navigation, index) {
            },
            onInit: function (tab, navigation, index) {
                //check number of tabs and fill the entire row
                var $total = navigation.find('li').length;
                $width = 100 / $total;
                $display_width = $(document).width();
                if ($display_width < 600 && $total > 3) {
                    $width = 50;
                }
                navigation.find('li').css('width', $width + '%');
                navigation.find('.process-line').css('width',$display_width*$width/100*0.3211+'px');
                navigation.css('display','block');
            },
            onTabClick: function (tab, navigation, index) {
                // Disable the posibility to click on tabs
                return false;
            },
            onTabShow: function (tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index + 1;

                var wizard = navigation.closest('.card-wizard');

                // If it's the last tab then hide the last button and show the finish instead
                if ($current >= $total) {
                    $(wizard).find('.btn-next').hide();
                    $(wizard).find('.btn-back').show();
                    $(wizard).find('.btn-finish').show();
                } else if ($current == 1) {
                    $(wizard).find('.btn-back').hide();
                    $(wizard).find('.btn-next').hide();
                    $(wizard).find('.btn-finish').hide();
                } else if($current == 2){
                    $(wizard).find('.btn-back').show();
                    $(wizard).find('.btn-next').hide();
                    $(wizard).find('.btn-finish').hide();
                }else {
                    $(wizard).find('.btn-back').show();
                    $(wizard).find('.btn-next').show();
                    $(wizard).find('.btn-finish').hide();
                }
            }
        });
        if(actBoolean.id){
            $('#wizardCard').bootstrapWizard('show',2);
        }
}





